#include "DynamicArray.h"

struct Student
{   
    Student(int id,const std::string& name,int score):id(id),name(name),score(score)
    {
        // std::cout<<"构造函数!\n";
    }
    int id;
    std::string name;
    int score;
};

void ShowStudent(void*p)
{
    Student *s = (Student*)p;
    std::cout<<s->id<<" "<<s->name<<" "<<s->score<<std::endl;
}
void FreeStudent(void*p)
{
    Student *s = (Student*)p;
    delete s;
}

bool CompareID(void*p1,void*p2)
{
    Student *s1 = (Student *)p1;
    Student *s2 = (Student *)p2;
    return s1->id > s2->id;
}

bool CompareName(void*p1,void*p2)
{
    Student *s1 = (Student *)p1;
    Student *s2 = (Student *)p2;
    return s1->name > s2->name;
}

bool CompareScore(void*p1,void*p2)
{
    Student *s1 = (Student *)p1;
    Student *s2 = (Student *)p2;
    return s1->score > s2->score;
}

bool isNameEqual(void *p1,void *p2)
{
    Student *s1 = (Student *)p1;
    char*s = (char*)p2;
    return s1->name == s;
}

bool isIDEqual(void*p1,void*p2)
{
    Student *s1 = (Student*)p1;
    long id = (long)p2;
    return s1->id == id;
}

bool isScoreEqual(void*p1,void*p2)
{
    Student *s1 = (Student*)p1;
    long score = (long)p2;
    return s1->score == score;
}

int main()
{
    
    // for(int i = 0; i < 10; i++)
    // {
    //     a.InsertTail(i+1);
    // }
    // for(int i = 0; i < 10; i++)
    // {
    //     a.InsertHead(i+1);
    // }
    // std::cout<<a;

    // // a.UpDataByElement(1,999);
    // a.Sort();
    // std::cout<<a;
    // a.Deduplicate();
    // for(int i = 0;i < 10;i++)
    //     a.InsertTail(i+1);

    // DynamicArray b;
    // for(int i = 0;i < 10;i++)
    //     b.InsertTail(i+1);
    // std::cout<<a;
    // std::cout<<b;
    // DynamicArray c = a.Merge(b);
    // std::cout<<c;
    DynamicArray a(FreeStudent);
    a.InsertTail(new Student(2,"zhangsan",10));
    a.InsertTail(new Student(3,"wangwu",80));
    a.InsertTail(new Student(1,"lisi",60));
    a.show(ShowStudent);
    // std::cout<<"按照ID排序:-------------\n";
    a.SetSortCallBack(CompareScore);
    a.Sort();
    a.show(ShowStudent);
    // std::cout<<"按照名称排序:--------------\n";
    // a.SetSortCallBack(CompareName);
    // a.Sort();
    // a.show(ShowStudent);
    std::cout<<"-----------\n";
    a.RemoveByElement((void*)80,isScoreEqual);
    a.show(ShowStudent);
    return 0;
}